package Action;

import java.util.List;


import com.opensymphony.xwork2.ActionSupport;

import Beans.Company;
import DAO.CompanyDao;
import DAO.ExpressDao;

@SuppressWarnings("serial")
public class CompanyAction extends ActionSupport{
	
	private List<Company> companies;

	CompanyDao companyDao = new CompanyDao();
	ExpressDao expressDao = new ExpressDao();

	private int companyID;
	private Company company = new Company();
	
	/**
	 * 编辑公司
	 * 
	 * @return
	 */
	public String editCompany() {
		company.setCompanyId(companyID);
		companyDao.edit(company);
		return "success";
	}

	/**
	 * 删除公司
	 * 
	 * @return
	 */
	public String deleteCompany() {
		if (expressDao.getCompanyExpressBranch(companyID).size()>0) {
		} else {
			company.setCompanyId(companyID);
			companyDao.delete(company);
		}
		return "success";
	}

	/**
	 * 新增公司
	 * 
	 * @return
	 */
	public String registerCompany() {
		companyDao.save(company);
		return "success";
	}

	
	/**
	 * 通过ID获取公司
	 */
	public String getCompanyById() {
		company=companyDao.getCompanyById(companyID);
		return "success";
	}
	
	/**
	 * 获取所有公司
	 */
	public String getAllcompany() {
		companies=companyDao.getAllcompany();
		return "success";
	}
	


	public List<Company> getCompanies() {
		return companies;
	}

	public void setCompanies(List<Company> companies) {
		this.companies = companies;
	}

	public int getCompanyID() {
		return companyID;
	}

	public void setCompanyID(int companyID) {
		this.companyID = companyID;
	}

	public Company getCompany() {
		return company;
	}

	public void setCompany(Company company) {
		this.company = company;
	}
	
	

}
